exports.queryAllUserInformation = function (req, res) {

    //获取参数信息
    var bodyParams = req.routeInfo.bodyParams;

    //返回结果
    var resultData = {};

    //存储命名空间
    var n_id = ""
    var fromUserId = ""

    //任务流创建
    async.waterfall([

        //查询命名空间
        //查询所有用户信息
        //查询是否存在会话列表
        (cb)=> {

            //查询是否已经存在
            db.field('n_id').where({
                "n_appid" : bodyParams.severAppId
            }).select("socket_namespace",(rs) => {
                //不存在
                if(rs.length == 0){
                    return RES.errorResponse(res,"此appId不存在");
                }
                n_id = rs[0].n_id
                cb();
            })

        },

        (cb)=> {

            db.where({
                "u_nid" : n_id,
                "u_is_delete" : 0
            }).order('u_create_time desc').select("socket_user",(rs) => {
                resultData = rs
                cb();
            })

        },

        (cb)=> {
            for(var i=0;i<resultData.length;i++){
                if(resultData[i].u_username == bodyParams.fromUserId){
                    fromUserId = resultData[i].u_username
                }
            }
            var task = [];
            resultData.forEach(function (item,i) {
                //创建每一个插入任务
                task.push(function (cb) {
                    db.where({
                        "s_send_id"     : item.u_username,
                        "s_receive_id"  : fromUserId,
                        "s_belongs_id"  : fromUserId,
                    }).select("socket_session",(rs) => {
                        if(rs.length != 0){
                            item.s_id = rs[0].s_id
                            cb();
                        }else{
                            db.where({
                                "s_send_id"     : fromUserId,
                                "s_receive_id"  : item.u_username,
                                "s_belongs_id"  : fromUserId,
                            }).select("socket_session",(rs) => {
                                if(rs.length != 0){
                                    item.s_id = rs[0].s_id
                                    cb();
                                }else{
                                    cb()
                                }
                            })
                        }
                    })
                });

            });
            async.parallel(task, () => {
                cb()
            });

        }
    ],()=> {
        //返回最终拼接结果
        RES.successResponse(res,resultData);

    });
    
}